package com.work.common.event;

import com.work.common.base.WorkThreadPool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

@Slf4j
@Component
public class TestUserAuthEvent {

    @EventListener
    public void handleUserAuthEvent(WorkEvent workEvent) {
        log.info("等待--->");
        CompletableFuture.runAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(5);
                log.info("执行完毕....{}", Thread.currentThread().getName());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }, WorkThreadPool.getThreadPool("测试事件线程池"));
        log.info("事件完成!");
    }
}
